package com.wujilee.wujileenetty.netty.io.channel;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.nio.channels.SelectableChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.util.Iterator;
import java.util.Set;

/**
 * 服务端channel 案例
 */
public class ServerChannel {
    public static void main(String[] args) throws IOException {
        // 接口绑定
        ServerSocketChannel  serverSocketChannel = ServerSocketChannel.open();
        serverSocketChannel.configureBlocking(false);
        serverSocketChannel.socket().bind(new InetSocketAddress("127.0.0.1",80080));

        Selector selector = Selector.open();
//        new Thread(new ReactorTask()).start();;
        SelectionKey register = serverSocketChannel.register(selector, SelectionKey.OP_READ);

        int select = selector.select();
        Set<SelectionKey> selectionKeys = selector.selectedKeys();

        Iterator<SelectionKey> iterator = selectionKeys.iterator();
        while (iterator.hasNext()){
            SelectionKey selectionKey = iterator.next();
            //
            if(selectionKey.isAcceptable()){

            }
        }

    }
}
